from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-29 14:11:31.155359
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 29, Mar, 2021
Time: 14:11:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.1703
Nobs: 245.000 HQIC: -47.9385
Log likelihood: 2897.16 FPE: 9.03253e-22
AIC: -48.4564 Det(Omega_mle): 6.30148e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.450160 0.128559 3.502 0.000
L1.Burgenland 0.070149 0.063469 1.105 0.269
L1.Kärnten -0.217696 0.054689 -3.981 0.000
L1.Niederösterreich 0.081541 0.141045 0.578 0.563
L1.Oberösterreich 0.219820 0.131306 1.674 0.094
L1.Salzburg 0.262686 0.071144 3.692 0.000
L1.Steiermark 0.141760 0.092643 1.530 0.126
L1.Tirol 0.114946 0.062372 1.843 0.065
L1.Vorarlberg -0.029920 0.057581 -0.520 0.603
L1.Wien -0.079621 0.118304 -0.673 0.501
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478987 0.153514 3.120 0.002
L1.Burgenland 0.005625 0.075789 0.074 0.941
L1.Kärnten 0.338322 0.065305 5.181 0.000
L1.Niederösterreich 0.108059 0.168424 0.642 0.521
L1.Oberösterreich -0.083054 0.156795 -0.530 0.596
L1.Salzburg 0.211470 0.084954 2.489 0.013
L1.Steiermark 0.127591 0.110627 1.153 0.249
L1.Tirol 0.136615 0.074479 1.834 0.067
L1.Vorarlberg 0.156187 0.068758 2.272 0.023
L1.Wien -0.467022 0.141268 -3.306 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301659 0.062544 4.823 0.000
L1.Burgenland 0.094863 0.030878 3.072 0.002
L1.Kärnten -0.015225 0.026606 -0.572 0.567
L1.Niederösterreich 0.048334 0.068619 0.704 0.481
L1.Oberösterreich 0.287981 0.063881 4.508 0.000
L1.Salzburg 0.015722 0.034612 0.454 0.650
L1.Steiermark 0.022301 0.045071 0.495 0.621
L1.Tirol 0.067457 0.030344 2.223 0.026
L1.Vorarlberg 0.083676 0.028013 2.987 0.003
L1.Wien 0.099034 0.057555 1.721 0.085
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212314 0.064062 3.314 0.001
L1.Burgenland 0.020506 0.031627 0.648 0.517
L1.Kärnten 0.008332 0.027252 0.306 0.760
L1.Niederösterreich 0.045645 0.070284 0.649 0.516
L1.Oberösterreich 0.400759 0.065431 6.125 0.000
L1.Salzburg 0.081318 0.035452 2.294 0.022
L1.Steiermark 0.139273 0.046165 3.017 0.003
L1.Tirol 0.048009 0.031080 1.545 0.122
L1.Vorarlberg 0.082570 0.028693 2.878 0.004
L1.Wien -0.038519 0.058952 -0.653 0.514
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.516773 0.125412 4.121 0.000
L1.Burgenland 0.079824 0.061915 1.289 0.197
L1.Kärnten 0.009699 0.053350 0.182 0.856
L1.Niederösterreich -0.032980 0.137593 -0.240 0.811
L1.Oberösterreich 0.135920 0.128092 1.061 0.289
L1.Salzburg 0.053599 0.069403 0.772 0.440
L1.Steiermark 0.094850 0.090376 1.050 0.294
L1.Tirol 0.212923 0.060845 3.499 0.000
L1.Vorarlberg 0.031267 0.056171 0.557 0.578
L1.Wien -0.092336 0.115408 -0.800 0.424
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198055 0.097066 2.040 0.041
L1.Burgenland -0.019581 0.047921 -0.409 0.683
L1.Kärnten -0.017721 0.041292 -0.429 0.668
L1.Niederösterreich -0.031981 0.106494 -0.300 0.764
L1.Oberösterreich 0.424107 0.099141 4.278 0.000
L1.Salzburg 0.006737 0.053716 0.125 0.900
L1.Steiermark -0.005873 0.069949 -0.084 0.933
L1.Tirol 0.160969 0.047093 3.418 0.001
L1.Vorarlberg 0.058120 0.043475 1.337 0.181
L1.Wien 0.233264 0.089323 2.611 0.009
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.247592 0.121250 2.042 0.041
L1.Burgenland 0.018461 0.059860 0.308 0.758
L1.Kärnten -0.063063 0.051580 -1.223 0.221
L1.Niederösterreich -0.059120 0.133027 -0.444 0.657
L1.Oberösterreich 0.013674 0.123842 0.110 0.912
L1.Salzburg 0.075900 0.067100 1.131 0.258
L1.Steiermark 0.339358 0.087377 3.884 0.000
L1.Tirol 0.456166 0.058826 7.754 0.000
L1.Vorarlberg 0.149338 0.054307 2.750 0.006
L1.Wien -0.172959 0.111578 -1.550 0.121
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129749 0.142894 0.908 0.364
L1.Burgenland 0.051305 0.070546 0.727 0.467
L1.Kärnten -0.069137 0.060787 -1.137 0.255
L1.Niederösterreich 0.193853 0.156773 1.237 0.216
L1.Oberösterreich -0.012989 0.145948 -0.089 0.929
L1.Salzburg 0.203706 0.079077 2.576 0.010
L1.Steiermark 0.127109 0.102974 1.234 0.217
L1.Tirol 0.052824 0.069327 0.762 0.446
L1.Vorarlberg 0.101133 0.064001 1.580 0.114
L1.Wien 0.226203 0.131496 1.720 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588626 0.077615 7.584 0.000
L1.Burgenland -0.040096 0.038318 -1.046 0.295
L1.Kärnten -0.025742 0.033017 -0.780 0.436
L1.Niederösterreich 0.010415 0.085154 0.122 0.903
L1.Oberösterreich 0.330018 0.079274 4.163 0.000
L1.Salzburg 0.017876 0.042952 0.416 0.677
L1.Steiermark -0.028844 0.055932 -0.516 0.606
L1.Tirol 0.087335 0.037656 2.319 0.020
L1.Vorarlberg 0.112250 0.034763 3.229 0.001
L1.Wien -0.043326 0.071424 -0.607 0.544
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137460 0.033878 0.159692 0.215752 0.054331 0.077341 -0.002367 0.152526
Kärnten 0.137460 1.000000 0.015879 0.204002 0.177204 -0.068356 0.157739 0.021467 0.305071
Niederösterreich 0.033878 0.015879 1.000000 0.247962 0.064950 0.291882 0.138277 0.029809 0.303072
Oberösterreich 0.159692 0.204002 0.247962 1.000000 0.300898 0.276138 0.087552 0.058356 0.134108
Salzburg 0.215752 0.177204 0.064950 0.300898 1.000000 0.151481 0.048403 0.090033 -0.002923
Steiermark 0.054331 -0.068356 0.291882 0.276138 0.151481 1.000000 0.110374 0.096984 -0.127024
Tirol 0.077341 0.157739 0.138277 0.087552 0.048403 0.110374 1.000000 0.164616 0.145279
Vorarlberg -0.002367 0.021467 0.029809 0.058356 0.090033 0.096984 0.164616 1.000000 0.002873
Wien 0.152526 0.305071 0.303072 0.134108 -0.002923 -0.127024 0.145279 0.002873 1.000000